<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>12.显示转换Booean类型</title>
</head>

<body>
  <script>

    //!! 转换
    let number = 0;
    // 两个感叹号，先转换为布尔类型，然后取两次反得到布尔类型
    console.log(!!number); // false
    console.log(Boolean(number)); // false

    let hd = '';
    console.log(!!hd); //false
    hd = 0;
    console.log(!!hd); //false
    hd = null;
    console.log(!!hd); //false
    hd = new Date("2020-2-22 10:33");
    console.log(!!hd); //true


    //  使用 Boolean 函数可以显式转换为布尔类型
    let hd2 = '';
    console.log(Boolean(hd2)); //false
    hd2 = 0;
    console.log(Boolean(hd2)); //false
    hd2 = null;
    console.log(Boolean(hd2)); //false
    hd2 = new Date("2020-2-22 10:33");
    console.log(Boolean(hd2)); //true
  </script>
</body>

</html>